package com.level.system.controller.EMR;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.level.system.base.ResponseBean;
import com.level.system.entity.emr.*;
import com.level.system.service.HISUploadService;
import com.level.system.util.MD5Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/api/hisToEmr")
public class HISUploadData {
    private final Logger log = LoggerFactory.getLogger(HISUploadData.class);
    @Resource
    private HISUploadService hisUploadService;
    /**
     * 同步病人基本信息
     * @param data
     * @return
     */
    @RequestMapping("/upPatientInfo")
    public ResponseBean<String> upPatientInfo(String data,String accessSecret,String sign){
        log.info("==========================传参："+data);
        JSONObject jo = JSONObject.parseObject(data);
//        jo.put("accessSecret",accessSecret);
//        if(sign.equals(MD5Util.MD5(jo.toString()))){
//
//        }
        PATIENT_INFORMATION bean = JSON.parseObject(jo.get("data").toString(),PATIENT_INFORMATION.class);
        ResponseBean<String> result = hisUploadService.upPatientInfo(bean);
        if(jo.get("cwbdxx")!=null){
            hisUploadService.upDicCWBDXX(jo.get("cwbdxx").toString());
        }
        log.info("==========================返回值："+result.getData());
        return hisUploadService.upPatientInfo(bean);
    }

    /**
     * 同步婴儿信息
     * @param data
     * @return
     */
    @RequestMapping("/upInfant")
    public ResponseBean<String> upInfant(String data){
        return hisUploadService.upInfant(data);
    }

    /**
     * 同步病区信息字典
     * @param data
     * @return
     */
    @RequestMapping("/upDicBQXX")
    public ResponseBean<String> upDicBQXX(String data){
        return hisUploadService.upDicBQXX(data);
    }

    /**
     * 同步病人手术信息字典
     * @param data
     * @return
     */
    @RequestMapping("/upPatientSSInfo")
    public ResponseBean<String> upPatientSSInfo(String data){
        return hisUploadService.upPatientSSInfo(data);
    }

    /**
     * 同步科室信息字典
     * @param data
     * @return
     */
    @RequestMapping("/upDicKSXX")
    public ResponseBean<String> upDicKSXX(String data){
        return hisUploadService.upDicKSXX(data);
    }

    /**
     * 同步（职工）医生信息
     * @param data
     * @return
     */
    @RequestMapping("/upDicYSXX")
    public ResponseBean<String> upDicYSXX(String data){
        log.info("==========================同步（职工）医生信息传参："+data);
        return hisUploadService.upDicYSXX(data);
    }


    /**
     * 同步门诊病人信息
     * @param data
     * @return
     */
    @RequestMapping("/upHisInfo")
    public ResponseBean<String> upHisInfo(String data){
        return hisUploadService.upHisInfo(data);
    }


    /**
     * 同步病人性质
     * @param data
     * @return
     */
    @RequestMapping("/upDicBRXZ")
    public ResponseBean<String> upDicBRXZ(String data){
        return hisUploadService.upDicBRXZ(data);
    }

    /**
     * 检验检查
     * @param data
     * @return
     */
    @RequestMapping("/queryRecLisInpatient")
    public ResponseBean<String> getRecLis(String data){
        return hisUploadService.queryRecLisInpatient(data);
    }

    /**
     * 检验检查样本信息
     * @param data
     * @return
     */
    @RequestMapping("/upreclis")
    public ResponseBean<String> upreclis(String data){
        return hisUploadService.upreclis(data);
    }

    /**
     * 检验检查
     * @param data
     * @return
     */
    @RequestMapping("/upreclisdetail")
    public ResponseBean<String> upreclisdetail(String data){
        return hisUploadService.upreclisdetail(data);
    }
}
